1027
class Solution {
    public int longestArithSeqLength(int[] nums) {
        int len = nums.length;
        int[][] dp = new int[len][len];
        MapInteger, Integer map = new HashMap();
        for (int i = 0; i  len; i++) {
            Arrays.fill(dp[i], 2);
            dp[i][i] = 1;
            
        }      
        int max = 2;
        for (int i = 0; i  len; i++) {
            for (int j = i+1; j  len; j++) {
                int tmp = nums[i]-(nums[j]-nums[i]);
                if (map.containsKey(tmp)) {
                    int m = map.get(tmp);
                    dp[i][j] = dp[m][i]+1;
                    max = Math.max(max, dp[i][j]);
                }
            }
            map.put(nums[i], i);
        }      
        return max;
    }
}